/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sse554_project3;

import java.io.*;
import java.util.TreeSet;

/**
 *
 * @author ascii42
 */
public class Dictionary {
    TreeSet<String> words;
    
    public Dictionary(){
        words = new TreeSet<String>();
        try {
            FileInputStream stream = new FileInputStream("./src/files/dictionary.txt");
            DataInputStream in = new DataInputStream(stream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String str;
            
            while((str = br.readLine())!=null){
                words.add(str);
            }
        } catch (FileNotFoundException e) {
            System.err.println("Error: " + e.getMessage());
        }
        catch(IOException e){
            System.err.println("Error: " + e.getMessage());
        }
    }
    public boolean isWord(String word){
        return words.contains(word.toLowerCase());
    }
    
    public boolean arePlacedInline(Cell[][] gameBoard){
        int newTileCount=0;
        for(int i=0; i<gameBoard.length;i++){
            for(int j=0;j<gameBoard[0].length;j++){
                // Count new tiles placed
                if(gameBoard[i][j].getTile()!=null && !gameBoard[i][j].getFixed()){
                    newTileCount++;
                }
            }
        }
        
        for(int i=0; i<gameBoard.length;i++){
            for(int j=0;j<gameBoard[0].length;j++){
                if(gameBoard[i][j].getTile()!=null && !gameBoard[i][j].getFixed()){
                    int rowTileCount=0;
                    int columnTileCount=0;
                    for(int ii=0;ii<gameBoard.length;ii++){
                        if(gameBoard[ii][j].getTile()!=null && !gameBoard[ii][j].getFixed()){
                            rowTileCount++;
                        }
                    }
                    for(int jj=0;jj<gameBoard[0].length;jj++){
                        if(gameBoard[i][jj].getTile()!=null && !gameBoard[i][jj].getFixed()){
                            columnTileCount++;
                        }
                    }
                    if(rowTileCount==newTileCount || columnTileCount==newTileCount){
                        return true;
                    }
                    return false;
                }
            }
        }
        return false;
    }
    
    public Boolean areConnected(Cell[][] gameBoard){
        int newTileCount=0;
        for(int i=0; i<gameBoard.length;i++){
            for(int j=0;j<gameBoard[0].length;j++){
                // Count new tiles placed
                if(gameBoard[i][j].getTile()!=null && !gameBoard[i][j].getFixed()){
                    newTileCount++;
                }
            }
        }
        
        return false;
    }
    public static void main(String[] args){
        Dictionary dictionary = new Dictionary();
        System.out.println("ABACAGF:" + dictionary.isWord("ABACAGF"));
        System.out.println("run:" + dictionary.isWord("run"));

    }

}
